<template>
    <layout>
        <el-page-header @back="$router.back()" content = "权限修改"></el-page-header>
        <el-tree :data="data" show-checkbox node-key="id"  :default-checked-keys="permissions" @check="handleCheck">
</el-tree>
    </layout>
</template>

<script>
export default {
    data() {
        return {
            data:[],
            permissions:[]
        }
    },
    created() {
        this.$http.get(`/permission/select`).then(res => {
            if(res.errcode == 0){
                this.data = res.data
            }
        })
        this.$http.get(`/role/get?id=${this.$route.params.id}`).then(res => {
            if(res.errcode == 0){
                this.permissions = res.data.permissionIds
            }
        })
    },
    methods: {
        handleCheck(checkedNodes,checkedKeys){
            this.$http.post(`/role/permission/batch`,{
                role_id: this.$route.params.id,
                ids:checkedKeys.checkedKeys
            }).then(res => {
                if(res.errcode == 0){
                    
                }
            })
        }
    }

}
</script>
<style>
.el-page-header{
    margin-bottom: 25px;
    margin-top: 5px;
}
</style>>
